package com.hung.trade.pay.server;

import com.hung.trade.common.constants.TradeEnums;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.XmlWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

/**
 * @author hungki
 * @createTime 2018-10-09 上午 12:02
 */
public class PayRestServer {
    public static void main(String[] args) {
        Server server =new Server(TradeEnums.RestServerEnum.PAY.getServerPort());

        ServletContextHandler servletContextHandler = new ServletContextHandler();
        servletContextHandler.setContextPath("/"+TradeEnums.RestServerEnum.PAY.getContextPath());

        XmlWebApplicationContext xmlWebApplicationContext = new XmlWebApplicationContext();
        xmlWebApplicationContext.setConfigLocation("classpath:spring/spring-pay-server.xml");
        servletContextHandler.addEventListener(new ContextLoaderListener(xmlWebApplicationContext));
        servletContextHandler.addServlet(new ServletHolder(new DispatcherServlet(xmlWebApplicationContext)),"/*");
        server.setHandler(servletContextHandler);
        try {
            server.start();
            server.join();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
